package com.qf.smsplatfrom.controller.advice;

import com.qf.smsplatfrom.constans.ResultCode;
import com.qf.smsplatfrom.dto.R;
import com.qf.smsplatfrom.exceptions.MyBaseException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MyExceptionAdvice {
    @ExceptionHandler(MyBaseException.class)
    public R processMyBaseException(MyBaseException m){
        int code = m.getCode();
        String msg = m.getMessage();
        return R.setError(code,msg,null);
    }

    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public R processHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException m){
        m.printStackTrace();
        return R.setError(ResultCode.HTTP_METHOD_NOT_ALLOW,"请求的方式不允许",null);
    }
    @ExceptionHandler(Exception.class)
    public R processMyBaseException(Exception m){
         m.printStackTrace();
        return R.setError(null);
    }
}
